efform_onload = function ()
{

	efgrid.submitInqu( "ef_grid_r", "ZM","ZMCN30","query");
	var _info = new EiInfo();
	
	efgrid_onRowClicked("ef_grid_r",0);
	$('#ef_region_detail').hide();
	$('#inqu_status1-0-fdBjdw').val($('#fdBjdw').val());
	$('#inqu_status1-0-fdYear').val($('#fdYear').val());
	$('#inqu_status1-0-fdMonth').val($('#fdMonth').val());
}; 
var ajax_callback1 = {
	onSuccess : function(eiInfo) {
		efwindow.hide(); 
		var grid = efgrid.getGridObject("ef_grid_d");
		grid.refresh(eiInfo);
	},
	onFail : function(eMsg) {}
};
button_query_onclick = function () 
{   	
	efgrid.submitInqu( "ef_grid_r", "ZM","ZMCN30","query");
}
button_update_onclick = function (){ 
/*	if (isSelected("ef_grid_r") == 0)return; 
	efgrid.submitForm( "ef_grid_r", "ZM","ZMCN30","update",true);*/
	var info = getSCZXEiInfos("ZMCN30","ef_grid_r");//ZMCN10 为EFFORM id，ef_grid_r为grid id（paintId）
	if (null != info) { 
//		EiCommunicator.send("ZMCN30", "validate", info, validate_callback);
		//先校验是否允许修改：如果明细有记录生效，不能修改主表
		EiCommunicator.send("ZMCN30", "validate1", info, validate1_callback);
	}
}
button_insert_onclick = function (){
/*	if (isSelected("ef_grid_r") == 0)return; 
	efgrid.submitForm( "ef_grid_r", "ZM","ZMCN30","insert",true);*/
	var info = getSCZXEiInfos("ZMCN30","ef_grid_r");//ZMCN10 为EFFORM id，ef_grid_r为grid id（paintId）
	if (null != info) { 
		EiCommunicator.send("ZMCN30", "validate", info, validate_callback);
	}
} 
button_delete_onclick = function (){
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		//先校验是否允许删除：如果明细有记录，不能删除主表
		if(r){
			//efgrid.submitForm( "ef_grid_r", "ZM","ZMCN30","delete",true);
			var info = getSCZXEiInfos("ZMCN30","ef_grid_r");
			if (null != info) { 
				EiCommunicator.send("ZMCN30", "validate1", info, validate1_callback);
			}
		}
	}); 
}

var fdBjdw,fdYear,fdMonth,fdCjdw,fdCjnr;
efgrid_onRowClicked = function( grid_id, row_index ){
	if(grid_id == "ef_grid_r"){ 
		$('#ef_region_detail').show();
		var grid = efgrid.getGridObject(grid_id);
		fdBjdw=grid.getCellValueByColumnName(row_index,"fdCjdw");
		fdYear=grid.getCellValueByColumnName(row_index,"fdYear");
		fdMonth=grid.getCellValueByColumnName(row_index,"fdMonth");
		fdCjnr=grid.getCellValueByColumnName(row_index,"fdCjnr");
		//隐藏/显示从表按钮 
		var info = new EiInfo();
		info.set("fdBjdw",fdBjdw); 
		info.set("fdYear",fdYear); 
		info.set("fdMonth",fdMonth);
		info.set("fdCjnr",fdCjnr);
		$('#fdBjdw').val(fdBjdw);
		$('#fdYear').val(fdYear);
		$('#fdMonth').val(fdMonth);
		$('#inqu_status1-0-fdBjdw').val(fdBjdw);
		$('#inqu_status1-0-fdYear').val(fdYear);
		$('#inqu_status1-0-fdMonth').val(fdMonth);
		$('#inqu_status-0-Year').val(fdYear);
		$('#inqu_status-0-Month').val(fdMonth);
		$('#inqu_status-0-Cjnr').val(fdCjnr);
		EiCommunicator.send("ZMCN32", "query", info, ajax_callback);  
	}
	if(grid_id == "ef_grid_d"){ 
		var grid = efgrid.getGridObject(grid_id); 
		var selectedRow=grid.getRowData(row_index);
		for(var item in selectedRow){
			var colname=item;
			var colvalue=selectedRow[item];
			$('#ef_region_inqu1').find('#inqu_status1-0-'+colname).val(colvalue);
		} 
	}
	
//	if(grid_id == "ef_grid_r"){ 
//		var grid = efgrid.getGridObject(grid_id);
//		fdBjdw=grid.getCellValueByColumnName(row_index,"fdCjdw");
//		fdYear=grid.getCellValueByColumnName(row_index,"fdYear");
//		fdMonth=grid.getCellValueByColumnName(row_index,"fdMonth");
//		var info = new EiInfo();
//		info.set("fdBjdw",fdBjdw); 
//		info.set("fdYear",fdYear); 
//		info.set("fdMonth",fdMonth);
//		$('#fdBjdw').val(fdBjdw);
//		$('#fdYear').val(fdYear);
//		$('#fdMonth').val(fdMonth);
//		$('#inqu_status1-0-fdBjdw').val(fdBjdw);
//		$('#inqu_status1-0-fdYear').val(fdYear);
//		$('#inqu_status1-0-fdMonth').val(fdMonth);
//		EiCommunicator.send("ZMCN32", "query", info, ajax_callback);  
//	}
//	if(grid_id == "ef_grid_d"){ 
//		var grid = efgrid.getGridObject(grid_id); 
//		var selectedRow=grid.getRowData(row_index);
//		for(var item in selectedRow){
//			var colname=item;
//			var colvalue=selectedRow[item];
//			$('#ef_region_inqu1').find('#inqu_status1-0-'+colname).val(colvalue);
//		} 
//	}
}
var ajax_callback= {
	onSuccess: function(eiInfo) { 
		 efwindow.hide();
		 var grid = efgrid.getGridObject("ef_grid_d");
		 grid.refresh(eiInfo);
	},
	onFail:function(eMsg)
	{
		EFAlert("新增失败，原因："+eMsg); 
	}
}

var validate_detail_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
//				 efwindow.hide();
//				 var grid = efgrid.getGridObject("ef_grid_d");
//				 grid.refresh(eiInfo);
				var oper="insert";
				if(eiInfo.get("efCurButtonEname")=="UPDATE1"){
					oper="update";
				}
				efgrid.submitForm("ef_grid_d", "ZM", "ZMCN32",oper, true);			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}
var validate_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
/*				 efwindow.hide();
				 var grid = efgrid.getGridObject("ef_grid_d");
				 grid.refresh(eiInfo);*/
				var oper="insert";
				if(eiInfo.get("efCurButtonEname")=="UPDATE"){
					oper="update";
				}
				efgrid.submitForm("ef_grid_r", "ZM", "ZMCN30",oper, true);
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}
var validate1_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
		/*				 efwindow.hide();
				 var grid = efgrid.getGridObject("ef_grid_r");
				 grid.refresh(eiInfo);*/
				var oper="delete";
				if(eiInfo.get("efCurButtonEname")=="UPDATE"){
					//进行重复性校验
					oper="update";
					EiCommunicator.send("ZMCN30", "validate", eiInfo, validate_callback);
				}else{
					efgrid.submitForm( "ef_grid_r", "ZM","ZMCN30","delete",true);
				}
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
	}
/********************************************************************************
 ***********************************从表操作**************************************** 
 ********************************************************************************/
//button_insert1_onclick = function (){
//	var info = getDetail("ef_region_inqu1","inqu_status1");
//	if (null != info) { 
//		EiCommunicator.send("ZMCN32", "insert", info, ajax_callbackconfirm);
//	} 
//}
//button_update1_onclick = function (){ 
//	var info = getDetail("ef_region_inqu1","inqu_status1");
//	if (null != info) {
//		EiCommunicator.send("ZMCN32", "update", info, ajax_callbackconfirm);
//	} 
//}
//button_delete1_onclick = function (){
//	var grid=isSelected("ef_grid_d");
//	if (grid == 0)return;  
//	EFConfirm('你确认要删除吗?', '确认框', function(r) {
//		if(r){
//			efgrid.submitForm( "ef_grid_d", "ZM","ZMCN32","delete",true);
//		}
//	}); 
//}  
//button_report_onclick = function (){
//	if (isSelected("ef_grid_d") == 0)
//		return; 
//	EFConfirm('你确认要上报吗?', '确认框', function(r) {
//		if(r)efgrid.submitForm( "ef_grid_d", "ZM","ZMCN32","report",true);
//	}); 
//}
//var ajax_callbackconfirm = {
//	onSuccess : function(eiInfo) {
//		var info = new EiInfo();
//		
//		info.set("fdBjdw",fdBjdw); 
//		info.set("fdYear",fdYear); 
//		info.set("fdMonth",fdMonth);
//		$('#fdBjdw').val(fdBjdw);
//		$('#fdYear').val(fdYear);
//		$('#fdMonth').val(fdMonth);
//		$('#inqu_status1-0-fdBjdw').val(fdBjdw);
//		$('#inqu_status1-0-fdYear').val(fdYear);
//		$('#inqu_status1-0-fdMonth').val(fdMonth);
//		EiCommunicator.send("ZMCN32", "query", info, ajax_callback);  
//	}, 
//	onFail:function(eMsg)
//	{
//		alert("确认失败，原因："+eMsg);
//	}
//}

button_insert1_onclick = function (){
	/*	var info = getDetail("ef_region_inqu1","inqu_status1");
		if (null != info) { 
			EiCommunicator.send("ZMCN21", "insert", info, ajax_callbackconfirm);
		} */
		//以下方式为行增
		if (isSelected("ef_grid_d") == 0)return; 
//		efgrid.submitForm( "ef_grid_d", "ZM","ZMCN10","insert1",true);
		//以下为行增有重复性校验
		var info = getSCZXEiInfos("ZMCN30","ef_grid_d");
		if (null != info) { 
			EiCommunicator.send("ZMCN32", "validate", info, validate_detail_callback);
		}
	}
	button_update1_onclick = function (){ 
		var grid=isSelected("ef_grid_d");
		if (grid == 0)return; 
		var rows=grid.getCheckedRows();
		for(var i=0;i<rows.length;i++)
		{
			if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
			{
				EFAlert("只能对草拟的记录进行删除！"); return;
			}
		}
		if (isSelected("ef_grid_d") == 0)return; 
		var info = getSCZXEiInfos("ZMCN30","ef_grid_d");
		if (null != info) { 
			EiCommunicator.send("ZMCN32", "validate", info, validate_detail_callback);
		}
		
	}
	button_delete1_onclick = function (){
		var grid=isSelected("ef_grid_d");
		if (grid == 0)return; 
		var rows=grid.getCheckedRows();
		for(var i=0;i<rows.length;i++)
		{
			if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
			{
				EFAlert("只能对草拟的记录进行删除！"); return;
			}
		}
		EFConfirm('你确认要删除吗?', '确认框', function(r) {
			if(r)efgrid.submitForm( "ef_grid_d", "ZM","ZMCN32","delete",true);
		}); 
	}
		

	button_report_onclick = function (){
		if (isSelected("ef_grid_d") == 0)
			return; 
		var grid=isSelected("ef_grid_d");
		var rows=grid.getCheckedRows();
		for(var i=0;i<rows.length;i++)
		{
			if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
			{
				EFAlert("该记录已经上报了！"); return;
			}
		}
		EFConfirm('你确认要上报吗?', '确认框', function(r) {
			if(r)efgrid.submitForm( "ef_grid_d", "ZM","ZMCN32","report",true);
		}); 
	}

	efgrid_afterAddNewRow = function(grid_id){ 
		var grid = efgrid.getGridObject(grid_id);
		var rows = grid.getCheckedRows();  
		if(grid_id=="ef_grid_d")
		{
//			var fdBjdw=$('#ef_grid_r-0-fdBjdw').val(); 
//			var fdYear=$('#ef_grid_r-0-fdYear').val(); 
//			var fdMonth=$('#ef_grid_r-0-fdMonth').val(); 
		   
			for(var i = 0 ; i < rows.length;i++){
				grid.setCellValue(rows[i],0,"草拟",TYPE_DATA);  
			}
		}
	}
/********************************************************************************
 ***********************************页签**************************************** 
 ********************************************************************************/
function fundiv(currentIndex,index){ 
	var info = new EiInfo(); 
	if(index ==0)
	{
	}else if(index ==1)
	{ 
		var frame = frames[0];
		frame.src = "DispatchAction.do?efFormEname=ZMCN31";
		efform.setStatus(0, "正在加载...");
	}
} 